package com.learning.spring.bean.injection.method.entity;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

import java.util.Date;
import java.util.StringJoiner;

/**
 * ClassName: UserBeanFactory
 * Description: 实体类
 * Date: 2020/7/22 9:52 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Setter
@Getter
public class UserBeanFactory implements BeanFactoryAware {
    private long id;
    private String name;
    private int age;
    private Date createTime;
    private Address address;

    private BeanFactory beanFactory;

    public Address getAddress() {
        return beanFactory.getBean(Address.class);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    @Override
    public String toString() {
        return new StringJoiner(", ", UserBeanFactory.class.getSimpleName() + "[", "]")
                .add("id=" + id)
                .add("name='" + name + "'")
                .add("age=" + age)
                .add("createTime=" + createTime)
                .add("address=" + address)
                .toString();
    }

}
